package com.share.finance.risk.third.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.finance.risk.third.mapper.LocalVariateConfMapper;
import com.share.finance.risk.third.model.db.LocalVariateConf;
import com.share.finance.risk.third.service.ILocalVariateConfService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 本地变量配置表  服务实现类
 * </p>
 *
 * @author author
 * @since 2022-12-25
 */

@Slf4j
@Service
public class LocalVariateConfServiceImpl extends ServiceImpl<LocalVariateConfMapper, LocalVariateConf> implements ILocalVariateConfService {
    @Resource
    private LocalVariateConfMapper localVariateConfMapper;

    private Map<String, LocalVariateConf> localVariateConfMap;

    @Override
    public Object init() {
        Map<String, LocalVariateConf> localVariateConfMap_ = new HashMap<>();
        List<LocalVariateConf> list = localVariateConfMapper.selectList(Wrappers.<LocalVariateConf>query().ge("status", "1"));
        for (LocalVariateConf item : list) {
            localVariateConfMap_.put(item.getFieldId(), item);
        }

        if (localVariateConfMap_ != null) {
            localVariateConfMap = localVariateConfMap_;
        }
        log.info("加载到的本地变量={}", JSON.toJSONString(localVariateConfMap));
        return localVariateConfMap;
    }

    @Override
    public LocalVariateConf getByFieldId(String fieldId) {
        return localVariateConfMap.get(fieldId);
    }
}
